home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: What is wrong with this loop?
- Date: Fri, 19 Apr 1996 22:38:49 -0400
- Organization: Not so good, but I'm working on it ;-)
- Distribution: world
- Message-ID: <64EexYhq04ND089yn@nando.net>
- References: <4l86la$1t9@uwm.edu>
- NNTP-Posting-Host: grail2204.nando.net
-
- In article <4l86la$1t9@uwm.edu>,
- mardavuy@alpha2.csd.uwm.edu (Mario David Uy) put down for all to see:
-
- >#include <stdio.h>
- >int main(void)
- >{
- > int dia;
- >
- > char cd;
- >
- > ...
- >
- > scanf("%c", &cd);
- > while (cd != 'm' || cd ! 'f' || cd != 'o')
-
- I assume you meant cd != 'f' above.
-
- > {
- > printf("Re-enter m, f, or o.\n");
- > scanf(%c", &cd);
- > }
- > ...
- >}
- >
- >It works fine, except that it gives me the printf() twice.
-
- Suppose you entered the letter a and hit enter. Since 'a'
- is not one of the 3 valid choices, printf() is invoked, the
- scanf() fetches the '\n' (which is also not one of the 3
- valid choices), so the printf() is invoked again ...
-